package startup

import (
	"shop-common/library/db"
	"shop-common/library/variables"
)

// SetupVars 加载变量
func SetupVars() error {
	if variables.MysqlSetting != nil && variables.MysqlSetting.Host != "" {
		_, err := db.NewMySQLWithGORM(variables.MysqlSetting)
		if err != nil {
			return err
		}
		variables.GormDB = db.DB
	}

	if variables.RedisSetting != nil && variables.RedisSetting.Addr != "" {
		redisClient, err := db.NewRedis(variables.RedisSetting)
		if err != nil {
			return err
		}
		variables.RedisConn = redisClient
	}
	return nil
}
